Selectable Elements

Description

Selectable elements give you the ability to add selectability to the rows of data displayed in a ViewBox control. This is done by defining a cursor in the ViewBox control, with the help of some CSS, and then implement this cursor in the template itself. The result is a cursor that can function like the cursor in, say, a list control.

images/selectable.png
A selected row of data generated from an SQL database and displayed in HTML.

For an in depth look at implementing selectable elements in a ViewBox control watch this video. The guide below also builds a ViewBox control with a selectable element and examines the construction of the html and CSS involved.

Create a ViewBox with Selectable Rows

  1. In the UX Builder's UX Controls page open the 'Data Controls' menu. Click on 'ViewBox' to add a viewbox control to the component.

    images/se.png
  2. In the properties list on the right click on the button next to the 'ViewBox properties'property, in the ViewBox Properties section. The ViewBox Builder will open.

    images/se2.png
  3. Open the 'Data Source' pane set the 'ViewBox type' property to 'Data'. This property is in the ViewBox Datasource section.

    images/se3.png
  4. Under the ViewBox Data section set the 'Datasource type' property to be 'Database Query'

    images/se4.png
  5. Set the Query type property to 'SQL query'.

    images/se5.png
  6. In the SQL Query section that appears click the button next to the 'Connection string' property. Set the Connection string to the 'Northwind' database.

    images/se6.png
  7. Click the button next to the 'Table name' property and select 'Customers'.

    images/se7.png
  8. Click the button next to the 'Fields' property and select the following fields: 'ContactName', 'Address', 'City', and 'Country'.

    images/se8.png
  9. Open the ViewBox Layout pane. Check the 'Freeform editor' radio button.

    images/se9.png
  10. Add the following HTML to the Freeform editor.

    <h2>{ContactName}</h2>
    <table cellspacing="0">
        <tr>
            <th>Address</th>
            <th>City</th>
            <th>Country</th>
        </tr>
        <tr a5-item='clickonrow'>
            <td>{Address}</td>
            <td>{City}</td>
            <td>{Country}</td>
        </tr>
    </table>
    images/se10.png
    The curly braces {} denote placeholders for the fields that we selected from the Customers table. The <tr></tr> tags represent table rows. The <th></th> tags are headings and the <td></td> tags contain the table data. The line 'a5-item='clickonrow' references an item in the Items pane that will be defined soon. This item will call a CSS class that will set the background color of the selected row.
  11. Open the CSS pane. Add the following CSS classes.

    .selectedRow {
        background-color:yellow;
        padding:0px;
        border:0px;
    }
    
    h2 {
        color:#5db0b7;
    }
    
    tr {
        text-align:left;
    }
    
    th {
        padding:11px;
        width:160px;
        text-align:left;
    }
    
    td {
        padding:11px;
        width:160px;
        text-align:left;
    }
    images/se11.png
    The selectedRow class represents the styling on the selected row. The remaining classes -- h2, tr, th, and td -- stylize the html table itself. This gives the table a more presentable appearance, aligning the text, setting the width of the table's cells, adding padding between cells, and setting the color of the header.
  12. Open the 'Items' pane and click the 'Add item' button. Name the item 'clickonrow'.

    images/se12.png
  13. Check the 'Selectable' checkbox.

    images/se13.png
  14. Next to the 'Selected class name' property write 'selectedRow'. Click OK to close the ViewBox control.

    images/se14.png
  15. Run the component in Live Preview

    images/se15.png
  16. Click on one of the rows containing the Address, City, and Country data. The row should highlight.

    images/se16.png